<script lang="ts" setup>
import MyBox from '@/components/MyBox.vue'
import MyChart from '@/components/MyChart.vue'
import { ref, watch } from 'vue'
const props = defineProps(['data'])

watch(
  () => props.data,
  (val) => {
    const { xList, yList, ratioList, legendList } = val
    options.value.legend.data = legendList
    options.value.xAxis[0].data = xList
    options.value.series[1].data = yList
    options.value.series[0].data = ratioList
    options.value.series[0].name = legendList[0]
    options.value.series[1].name = legendList[1]
    //取2组数据中的最大值
    const tempArr = [...yList, ...ratioList]
    const tempMax = Math.max(...tempArr)
    const maxValue = Math.ceil(tempMax / 100) * 100
    options.value.yAxis[0].max = maxValue
  }
)
const options = ref({
  grid: {
    right: 30,
    top: 40,
    bottom: 30
  },
  tooltip: {
    trigger: 'axis',
    confine: true,
    axisPointer: {
      type: 'shadow',
      crossStyle: {
        color: '#999'
      }
    }
  },
  legend: {
    textStyle: {
      color: '#ebeef5',
      fontSize: 16
    },
    data: []
  },
  xAxis: [
    {
      type: 'category',
      data: ['09-30', '10-01', '10-02', '10-03', '10-04', '10-05'],
      axisPointer: {
        type: 'shadow'
      },
      axisLabel: {
        color: '#ebeef5',
        fontSize: 22
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#182758',
          width: 2
        }
      },
      splitLine: {
        show: false
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      max: 6000,
      interval: 1500,
      name: '',
      nameTextStyle: {
        color: '#ebeef5',
        fontSize: 16,
        align: 'right',
        padding: [0, 5, 8, 0]
      },
      axisLabel: {
        formatter: '{value}',
        color: '#ebeef5',
        fontSize: 22,
        align: 'right'
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#182758',
          width: 2
        }
      },
      splitLine: {
        show: false
      }
    },
    {
      type: 'value',
      name: '',
      nameTextStyle: {
        color: '#ebeef5'
      },
      axisLabel: {
        show: false,
        formatter: '{value}',
        color: '#ebeef5',
        fontSize: 16
      },
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      }
    }
  ],
  series: [
    {
      name: '',
      type: 'line',
      color: '#406fc2',
      label: {
        show: true,
        position: 'top',
        color: '#fff',
        fontSize: 18
      },
      // smooth: true,
      tooltip: {
        valueFormatter: function (value: any) {
          return value + ''
        }
      },
      data: [5703, 5263, 5952, 5571, 5787, 6000]
    },
    {
      name: '',
      type: 'line',
      color: '#ec7626',
      label: {
        show: true,
        position: 'top',
        color: '#fff',
        fontSize: 18
      },
      // smooth: true,
      tooltip: {
        valueFormatter: function (value: any) {
          return value + ''
        }
      },
      data: [3547, 3245, 3687, 3426, 3589, 3768]
    },
    {
      name: '',
      type: 'line',
      color: '#fbbf24',
      label: {
        show: true,
        position: 'top',
        color: '#fff',
        fontSize: 18
      },
      // smooth: true,
      tooltip: {
        valueFormatter: function (value: any) {
          return value + ''
        }
      },
      data: [2156, 2018, 2265, 2145, 2198, 2388]
    },
  ]
})
</script>
<template>
  <MyBox class="yield-comparison" title="分拣卷数趋势">
    <template v-slot:main>
      <MyChart height="260px" :option="options" />
    </template>
  </MyBox>
</template>
<style scoped>
.yield-comparison {
  width: calc(65% - 30px);
}
</style>
